package org.ilovecode.display 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import gs.TweenLite;
	
	import org.ilovecode.events.ApartmentEvent;
	import org.ilovecode.screen.FloorScreen;
	import org.ilovecode.screen.Screen;
	
	/**
	 * ...
	 * @author Vjekoslav Ratkajec
	 */
	public class FloorLayoutBase extends FloorScreen {
		
		protected var _baloonForSale:FloorLayoutBaseBaloon;
		protected var _baloonSold:FloorLayoutBaseBaloon;
		protected var _baloonReserved:FloorLayoutBaseBaloon;
		
		protected var duration:Number = 0.3;
		
		public function FloorLayoutBase(type:String="", group:String="", name:String="") {
			super(type, group, name);
		}
		
		override protected function construct():void
		{
			super.construct();
			
			_baloonForSale = FloorLayoutBaseBaloon(this.getChildByName("baloonForSale"));
			_baloonSold = FloorLayoutBaseBaloon(this.getChildByName("baloonSold"));
			_baloonReserved = FloorLayoutBaseBaloon(this.getChildByName("baloonReserved"));
		}
		
		override protected function initText():void
		{
			super.initText();
		}
		
		override protected function initUI():void
		{
			super.initUI();
			
			initBaloon(_baloonForSale);
			initBaloon(_baloonSold);
			initBaloon(_baloonReserved);
			this._baloonSold.priceTextField.visible = false;
		}
		
		/*
		protected function setBaloons(forSale:FloorLayoutBaseBaloon, sold:FloorLayoutBaseBaloon, reserved:FloorLayoutBaseBaloon):void {
			this._baloonForSale = forSale;
			this._baloonSold = sold;
			this._baloonSold.priceTextField.visible = false;
			this._baloonReserved = reserved;
		}*/
		
		protected function initRoom(room:DisplayObject):void {
			room.alpha = 0;
			//room.buttonMode = true;
			/*room.addEventListener(MouseEvent.MOUSE_OVER, roomMouseOver);
			room.addEventListener(MouseEvent.MOUSE_OUT, roomMouseOut);
			room.addEventListener(MouseEvent.CLICK, roomClick);*/
		}
		
		protected function initBaloon(baloon:FloorLayoutBaseBaloon):void {
			baloon.mouseEnabled = false;
			baloon.mouseChildren = false;
			baloon.scaleX = baloon.scaleY = baloon.alpha = 0;
		}
		
		protected function roomMouseOver(event:ApartmentEvent):void {
			//TweenLite.to(event.currentTarget, duration, { alpha:1 } );
			//toggleBaloon(FloorLayoutBaseRoom(event.currentTarget), true);
		}
		
		protected function roomMouseOut(event:ApartmentEvent):void {
			//TweenLite.to(event.currentTarget, duration, { alpha:0 } );
			//toggleBaloon(FloorLayoutBaseRoom(event.currentTarget), false);
		}
		
		protected function roomClick(event:ApartmentEvent):void {
			throw new Error("Child must override click function");
		}
		
		protected function toggleBaloon(room:FloorLayoutBaseRoom, show:Boolean):void {
			var baloon:FloorLayoutBaseBaloon;
			if (room.status == "stan za prodaju") {
				baloon = _baloonForSale;
			} else if (room.status == "prodano") {
				baloon = _baloonSold;
			} else if (room.status == "rezervirano") {
				baloon = _baloonReserved;
			}
			
			baloon.setText(room.code);
			baloon.setPrice(room.price);
			//baloon.x = room.x + room.width / 2;
			//baloon.y = room.y + room.height / 2;
			if (show) {
				showBaloon(baloon);
			} else {
				hideBaloon(baloon);
			}
		}
		
		protected function showBaloon(baloon:FloorLayoutBaseBaloon):void {
			TweenLite.to(baloon, duration, { alpha:1, scaleX:1, scaleY:1 } );
		}
		
		protected function hideBaloon(baloon:FloorLayoutBaseBaloon):void {
			TweenLite.to(baloon, duration, { alpha:0, scaleX:0, scaleY:0 } );
		}
		
		
	}

}